# coding: utf-8

str_utf8 = "hi 段"
puts str_utf8.size								# 4
puts str_utf8.bytesize							# 6
puts str_utf8 .encoding 						# UTF-8
str_utf8.each_byte {|b| print "%02X," % [b]}  	# 68,69,20,E6,AE,B5,
puts

puts

str_gb2312 = "hi 段".encode("gb2312")
puts str_gb2312.size							# 4
puts str_gb2312.bytesize						# 5
puts str_gb2312 .encoding 						# GB2312
str_gb2312.each_byte {|b| print "%02X," % [b]} 	# 68,69,20,B6,CE,
puts

str_ascii = "hi ".encode("ascii")
str_utf8 = "段"
puts str_ascii.encoding
puts str_utf8.encoding
puts Encoding.compatible?(str_ascii.encoding, str_utf8.encoding)
puts (str_ascii + str_utf8).encoding
puts (str_utf8 + str_ascii).encoding

puts "段" # 段
puts "\xE6\xAE\xB5" # 段
puts "\u6BB5" # 段

# 默认是UTF8编码，不用处理。
puts "段"
# 执行windows命令必须使用GB2312编码。
command = "echo 段".encode("GB2312")
# 命令执行的结果想输出到Sublime必须使用UTF8编码。
puts `#{command}`.encode("utf-8")